﻿// <copyright file="TimeTrackerXML.cs" company="BerlinSoft">
// Copyright (c) 2009 All Right Reserved
// </copyright>
// <author>Wernfried Schwenkner</author>
// <email>wernfried@schwenkner.de</email>
// <date>2009-10-21</date>
// <summary>
// Contains the TimeTrackerXML class.
// </summary>

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace SenseTimeTracker.Export
{
	/// <summary>
	/// Root class for xml exports
	/// </summary>
	[XmlRoot("TimeTracker")]
	public class TimeTrackerXML
	{
		/// <summary>
		/// List of all clients
		/// </summary>
		private List<Client> clients = new List<Client>();

		/// <summary>
		/// Gets or sets the clients collection
		/// </summary>
		public List<Client> Clients
		{
			get { return clients; }
			set { clients = value; }
		}

		/// <summary>
		/// Serializes the export file
		/// </summary>
		/// <param name="fileName">File name to write the export to</param>
		public void Serialize(string fileName)
		{
			XmlSerializer serializer = new XmlSerializer(typeof(TimeTrackerXML));
			TextWriter writer = new StreamWriter(fileName);
			serializer.Serialize(writer, this);
			writer.Close();
		}

		/// <summary>
		/// Client class for XML export
		/// </summary>
		public class Client
		{
			/// <summary>
			/// List of all projects
			/// </summary>
			private List<Project> projects = new List<Project>();

			/// <summary>
			/// Gets or sets the name of the client
			/// </summary>
			[XmlAttribute]
			public string Name { get; set; }

			/// <summary>
			/// Gets or sets the type of the client
			/// </summary>
			[XmlAttribute]
			public string Type { get; set; }

			/// <summary>
			/// Gets or sets the id of the client
			/// </summary>
			[XmlIgnore]
			public Guid Id { get; set; }

			/// <summary>
			/// Gets or sets the projects collection
			/// </summary>
			public List<Project> Projects
			{
				get { return projects; }
				set { projects = value; }
			}
		}

		/// <summary>
		/// Project class for XML export
		/// </summary>
		public class Project
		{
			/// <summary>
			/// List of all tasks
			/// </summary>
			private List<Task> tasks = new List<Task>();

			/// <summary>
			/// Gets or sets the name of the project
			/// </summary>
			[XmlAttribute]
			public string Name { get; set; }

			/// <summary>
			/// Gets or sets the numer of the project
			/// </summary>
			[XmlAttribute]
			public string Number { get; set; }

			/// <summary>
			/// Gets or sets the type of the project
			/// </summary>
			[XmlAttribute]
			public string Type { get; set; }

			/// <summary>
			/// Gets or sets the id of the project
			/// </summary>
			[XmlIgnore]
			public Guid Id { get; set; }

			/// <summary>
			/// Gets or sets the tasks collection
			/// </summary>
			public List<Task> Tasks
			{
				get { return tasks; }
				set { tasks = value; }
			}
		}

		/// <summary>
		/// Task class for XML export
		/// </summary>
		public class Task
		{
			/// <summary>
			/// List of all time records
			/// </summary>
			private List<TimeCard> timeCards = new List<TimeCard>();

			/// <summary>
			/// Gets or sets the name of the task
			/// </summary>
			[XmlAttribute]
			public string Name { get; set; }

			/// <summary>
			/// Gets or sets the number of the task
			/// </summary>
			[XmlAttribute]
			public string Number { get; set; }

			/// <summary>
			/// Gets or sets the type of the task
			/// </summary>
			[XmlAttribute]
			public string Type { get; set; }

			/// <summary>
			/// Gets or sets the description of the task
			/// </summary>
			[XmlElement]
			public string Description { get; set; }

			/// <summary>
			/// Gets or sets the location of the task
			/// </summary>
			[XmlAttribute]
			public string Location { get; set; }

			/// <summary>
			/// Gets or sets the estimate time of the task
			/// </summary>
			[XmlAttribute]
			public int Estimate { get; set; }

			/// <summary>
			/// Gets or sets the id of the task
			/// </summary>
			[XmlIgnore]
			public Guid Id { get; set; }

			/// <summary>
			/// Gets or sets the time cards collection
			/// </summary>
			public List<TimeCard> TimeCards
			{
				get { return timeCards; }
				set { timeCards = value; }
			}
		}

		/// <summary>
		/// Timecard class for XML export
		/// </summary>
		public class TimeCard
		{
			/// <summary>
			/// Gets or sets the description of the time card
			/// </summary>
			[XmlElement]
			public string Description { get; set; }

			/// <summary>
			/// Gets or sets the details of the time card
			/// </summary>
			[XmlElement]
			public string Details { get; set; }

			/// <summary>
			/// Gets or sets the start time of the time card
			/// </summary>
			[XmlAttribute]
			public DateTime StartTime { get; set; }

			/// <summary>
			/// Gets or sets the final of the time card
			/// </summary>
			[XmlAttribute]
			public DateTime FinalTime { get; set; }
		}
	}
}
